package com.wkr.send;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

@Component
public class Sender {

    @Autowired
    @Qualifier("jmsTemplate")
    private JmsTemplate jmsQueueTemplate;


    //发送消息
    public void sendMessage(final String message) {
        System.out.println("1："+jmsQueueTemplate);
        System.out.println("Sender发送消息："+message);
        jmsQueueTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                return session.createTextMessage(message);
            }
        });
        System.out.println("发送完毕！");
    }


}
